using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text.RegularExpressions;

namespace Xfinity.Console
{
    public static class CommandLineArgumentTokeniser
    {
        private static Dictionary<string, string> parameters = new Dictionary<string, string>();
        static CommandLineArgumentTokeniser()
        {
            string commandline = Process.GetCurrentProcess().StartInfo.Arguments;
            Regex breakup = new Regex("(['\"\"][^\"\"]+['\"\"])\\s*|([^\\s+)\\s*", RegexOptions.IgnoreCase);
            MatchCollection matches = breakup.Matches(commandline);
            List<string> list = new List<string>();
            for (int i = 1; i < matches.Count - 1; i++)
            {
                list.Add(matches[i].Value);
            }
            string[] args = list.ToArray();

            Regex tokeniser = new Regex(@"^([/-]|--){1}(?<name>\w+)([:=])?(?<value>.+)?$", RegexOptions.IgnoreCase);

            char[] trimChars = { '"', '\'' };
            string currentToken = null;
            foreach (string argument in args)
            {
                Match match = tokeniser.Match(argument);
                if (!match.Success)
                {
                    if (currentToken != null)
                    {
                        //parameters[currentToken] =
                    }
                }
            }

        }

        public static Dictionary<string, string> Parameters
        {
            get { return parameters; }
        }
    }
}
